/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1160.breakaway;

import com.team1160.breakaway.api.Constants;
import com.team1160.breakaway.input.StructuredInput;
import com.team1160.breakaway.pid.PID;
import com.team1160.breakaway.stateManager.MergeEngine;
import com.team1160.breakaway.stateManager.TaskManager;

/**
 *
 * @author Saketh Kasibatla
 */
public class Merger extends MergeEngine{
    protected StructuredInput structIn;
    protected PID pid = new PID();

    public Merger(TaskManager m,StructuredInput in){
        super(m);
        this.structIn=in;
    }



    public void merge(StructuredInput.Param input) {
        double turnValue=input.getMove()+this.pid.calculate(input.getAxis(Constants.X_AXIS), input.getTurn());
        double moveValue=input.getMove()+this.pid.calculate(input.getAxis(Constants.Y_AXIS), input.getMove());
        if(input.getButton(Constants.BOTTOM_TOP_RIGHT-1)){
            input.setMove(0);
            input.setTurn(0);
        } else {
            input.setMove(moveValue);
            input.setTurn(turnValue);
        }
    }

    public void execute(StructuredInput.Param input) {
        this.MANAGER.drive(input.getMove(), input.getTurn());
        if(input.getButton(Constants.TRIGGER))
            this.MANAGER.shoot();
        
    }
    
    //Accessor Methods
    ////////////////////////////////////////////////////////////////////////////
    public StructuredInput.Param getParam(){
        return this.structIn.getCurrent(this.getMove(), this.getTurn());
    }

    public double getMove(){
        return ((Robot)this.MANAGER).getMove();
    }


    public double getTurn(){
        return ((Robot)this.MANAGER).getTurn();
    }

}
